import ctp_md_api as md
import ctp_td_api as td
import time


def OnTick(UpdateTime,InstrumentID,LastPrice):
    print('行情推送:'+ UpdateTime + ',品种:'+ InstrumentID + ',最新价格:'  ,LastPrice)
    #ctp_trade = td.zyc_ctptd
    #ctp_trade.qryPosition()
    i = 0

    time.sleep(1)


    #ctp_trade.buy('rb1812',4238,1,'买入','开仓')



ctp_trade = td.zyc_ctptd()
ctp_market = md.zyc_ctpmd()
futures = "a1901"
ctp_trade.connect('15910793600', 'zjh0923', '9999', 'tcp://180.168.146.187:10011')
#ctp_market.connect('15910793600', 'zjh0923', '9999', 'tcp://180.168.146.187:10011')


i = 0
while i < 5:
    if ctp_trade.isconnected == True:
        break
    time.sleep(1)
    i += 1
i = 0

# ---

ctp_trade.qryPosition()
time.sleep(5)
while i < 5:
    if ctp_market.isconnected == True:
        ctp_market.subscribeMarketData(futures)
        break
    time.sleep(1)
    i += 1

while True:
    pass

